<template>
  <el-dialog
    :title="!dataForm.no ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="厂家名称" prop="cpyname">
      <el-input v-model="dataForm.cpyname" placeholder="厂家名称"></el-input>
    </el-form-item>
    <el-form-item label="设备名称" prop="cncname">
      <el-input v-model="dataForm.cncname" placeholder="设备名称"></el-input>
    </el-form-item>
    <el-form-item label="设备类型" prop="cnctype">
      <el-input v-model="dataForm.cnctype" placeholder="设备类型"></el-input>
    </el-form-item>
    <el-form-item label="工作状态" prop="status">
      <el-input v-model="dataForm.status" placeholder="工作状态"></el-input>
    </el-form-item>
    <el-form-item label="报警" prop="alarm">
      <el-input v-model="dataForm.alarm" placeholder="报警"></el-input>
    </el-form-item>
    <el-form-item label="机械坐标X" prop="machposx">
      <el-input v-model="dataForm.machposx" placeholder="机械坐标X"></el-input>
    </el-form-item>
    <el-form-item label="机械坐标Y" prop="machposy">
      <el-input v-model="dataForm.machposy" placeholder="机械坐标Y"></el-input>
    </el-form-item>
    <el-form-item label="机械坐标Z" prop="machposz">
      <el-input v-model="dataForm.machposz" placeholder="机械坐标Z"></el-input>
    </el-form-item>
    <el-form-item label="绝对坐标X" prop="absposx">
      <el-input v-model="dataForm.absposx" placeholder="绝对坐标X"></el-input>
    </el-form-item>
    <el-form-item label="绝对坐标Y" prop="absposy">
      <el-input v-model="dataForm.absposy" placeholder="绝对坐标Y"></el-input>
    </el-form-item>
    <el-form-item label="绝对坐标Z" prop="absposz">
      <el-input v-model="dataForm.absposz" placeholder="绝对坐标Z"></el-input>
    </el-form-item>
    <el-form-item label="相对坐标X" prop="relposx">
      <el-input v-model="dataForm.relposx" placeholder="相对坐标X"></el-input>
    </el-form-item>
    <el-form-item label="相对坐标Y" prop="relposy">
      <el-input v-model="dataForm.relposy" placeholder="相对坐标Y"></el-input>
    </el-form-item>
    <el-form-item label="相对坐标Z" prop="relposz">
      <el-input v-model="dataForm.relposz" placeholder="相对坐标Z"></el-input>
    </el-form-item>
    <el-form-item label="剩余坐标X" prop="remposx">
      <el-input v-model="dataForm.remposx" placeholder="剩余坐标X"></el-input>
    </el-form-item>
    <el-form-item label="剩余坐标Y" prop="remposy">
      <el-input v-model="dataForm.remposy" placeholder="剩余坐标Y"></el-input>
    </el-form-item>
    <el-form-item label="剩余坐标Z" prop="remposz">
      <el-input v-model="dataForm.remposz" placeholder="剩余坐标Z"></el-input>
    </el-form-item>
    <el-form-item label="当前程序号" prop="curpgm">
      <el-input v-model="dataForm.curpgm" placeholder="当前程序号"></el-input>
    </el-form-item>
    <el-form-item label="运行时间" prop="runtime">
      <el-input v-model="dataForm.runtime" placeholder="运行时间"></el-input>
    </el-form-item>
    <el-form-item label="循环时间" prop="cycsec">
      <el-input v-model="dataForm.cycsec" placeholder="循环时间"></el-input>
    </el-form-item>
    <el-form-item label="进给实际转速" prop="actfeed">
      <el-input v-model="dataForm.actfeed" placeholder="进给实际转速"></el-input>
    </el-form-item>
    <el-form-item label="切割电流" prop="cutcurrent">
      <el-input v-model="dataForm.cutcurrent" placeholder="切割电流"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          no: 0,
          cpyname: '',
          cncname: '',
          cnctype: '',
          status: '',
          alarm: '',
          machposx: '',
          machposy: '',
          machposz: '',
          absposx: '',
          absposy: '',
          absposz: '',
          relposx: '',
          relposy: '',
          relposz: '',
          remposx: '',
          remposy: '',
          remposz: '',
          curpgm: '',
          runtime: '',
          cycsec: '',
          actfeed: '',
          cutcurrent: ''
        },
        dataRule: {
          cpyname: [
            { required: true, message: '厂家名称不能为空', trigger: 'blur' }
          ],
          cncname: [
            { required: true, message: '设备名称不能为空', trigger: 'blur' }
          ],
          cnctype: [
            { required: true, message: '设备类型不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '工作状态不能为空', trigger: 'blur' }
          ],
          alarm: [
            { required: true, message: '报警不能为空', trigger: 'blur' }
          ],
          machposx: [
            { required: true, message: '机械坐标X不能为空', trigger: 'blur' }
          ],
          machposy: [
            { required: true, message: '机械坐标Y不能为空', trigger: 'blur' }
          ],
          machposz: [
            { required: true, message: '机械坐标Z不能为空', trigger: 'blur' }
          ],
          absposx: [
            { required: true, message: '绝对坐标X不能为空', trigger: 'blur' }
          ],
          absposy: [
            { required: true, message: '绝对坐标Y不能为空', trigger: 'blur' }
          ],
          absposz: [
            { required: true, message: '绝对坐标Z不能为空', trigger: 'blur' }
          ],
          relposx: [
            { required: true, message: '相对坐标X不能为空', trigger: 'blur' }
          ],
          relposy: [
            { required: true, message: '相对坐标Y不能为空', trigger: 'blur' }
          ],
          relposz: [
            { required: true, message: '相对坐标Z不能为空', trigger: 'blur' }
          ],
          remposx: [
            { required: true, message: '剩余坐标X不能为空', trigger: 'blur' }
          ],
          remposy: [
            { required: true, message: '剩余坐标Y不能为空', trigger: 'blur' }
          ],
          remposz: [
            { required: true, message: '剩余坐标Z不能为空', trigger: 'blur' }
          ],
          curpgm: [
            { required: true, message: '当前程序号不能为空', trigger: 'blur' }
          ],
          runtime: [
            { required: true, message: '运行时间不能为空', trigger: 'blur' }
          ],
          cycsec: [
            { required: true, message: '循环时间不能为空', trigger: 'blur' }
          ],
          actfeed: [
            { required: true, message: '进给实际转速不能为空', trigger: 'blur' }
          ],
          cutcurrent: [
            { required: true, message: '切割电流不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.no = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.no) {
            this.$http({
              url: this.$http.adornUrl(`/cuttingmachinehisdata/cuttingmachinehisdata/info/${this.dataForm.no}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.cpyname = data.cuttingmachineHisdata.cpyname
                this.dataForm.cncname = data.cuttingmachineHisdata.cncname
                this.dataForm.cnctype = data.cuttingmachineHisdata.cnctype
                this.dataForm.status = data.cuttingmachineHisdata.status
                this.dataForm.alarm = data.cuttingmachineHisdata.alarm
                this.dataForm.machposx = data.cuttingmachineHisdata.machposx
                this.dataForm.machposy = data.cuttingmachineHisdata.machposy
                this.dataForm.machposz = data.cuttingmachineHisdata.machposz
                this.dataForm.absposx = data.cuttingmachineHisdata.absposx
                this.dataForm.absposy = data.cuttingmachineHisdata.absposy
                this.dataForm.absposz = data.cuttingmachineHisdata.absposz
                this.dataForm.relposx = data.cuttingmachineHisdata.relposx
                this.dataForm.relposy = data.cuttingmachineHisdata.relposy
                this.dataForm.relposz = data.cuttingmachineHisdata.relposz
                this.dataForm.remposx = data.cuttingmachineHisdata.remposx
                this.dataForm.remposy = data.cuttingmachineHisdata.remposy
                this.dataForm.remposz = data.cuttingmachineHisdata.remposz
                this.dataForm.curpgm = data.cuttingmachineHisdata.curpgm
                this.dataForm.runtime = data.cuttingmachineHisdata.runtime
                this.dataForm.cycsec = data.cuttingmachineHisdata.cycsec
                this.dataForm.actfeed = data.cuttingmachineHisdata.actfeed
                this.dataForm.cutcurrent = data.cuttingmachineHisdata.cutcurrent
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/cuttingmachinehisdata/cuttingmachinehisdata/${!this.dataForm.no ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'no': this.dataForm.no || undefined,
                'cpyname': this.dataForm.cpyname,
                'cncname': this.dataForm.cncname,
                'cnctype': this.dataForm.cnctype,
                'status': this.dataForm.status,
                'alarm': this.dataForm.alarm,
                'machposx': this.dataForm.machposx,
                'machposy': this.dataForm.machposy,
                'machposz': this.dataForm.machposz,
                'absposx': this.dataForm.absposx,
                'absposy': this.dataForm.absposy,
                'absposz': this.dataForm.absposz,
                'relposx': this.dataForm.relposx,
                'relposy': this.dataForm.relposy,
                'relposz': this.dataForm.relposz,
                'remposx': this.dataForm.remposx,
                'remposy': this.dataForm.remposy,
                'remposz': this.dataForm.remposz,
                'curpgm': this.dataForm.curpgm,
                'runtime': this.dataForm.runtime,
                'cycsec': this.dataForm.cycsec,
                'actfeed': this.dataForm.actfeed,
                'cutcurrent': this.dataForm.cutcurrent
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
